package com.longshine.plc.ui;

import com.longshine.util.NumberUtil;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import org.jdesktop.layout.GroupLayout;
import org.jdesktop.layout.GroupLayout.ParallelGroup;
import org.jdesktop.layout.GroupLayout.SequentialGroup;

public class BerthStationSwitchPanel extends OwnPanel
{
  private ButtonGroup buttonGroup1;
  private ButtonGroup buttonGroup10;
  private ButtonGroup buttonGroup11;
  private ButtonGroup buttonGroup2;
  private ButtonGroup buttonGroup3;
  private ButtonGroup buttonGroup4;
  private ButtonGroup buttonGroup5;
  private ButtonGroup buttonGroup6;
  private ButtonGroup buttonGroup7;
  private ButtonGroup buttonGroup8;
  private ButtonGroup buttonGroup9;
  private JButton jButton4;
  private JButton jButton5;
  private JLabel jLabel10;
  private JLabel jLabel11;
  private JLabel jLabel12;
  private JLabel jLabel2;
  private JLabel jLabel3;
  private JLabel jLabel32;
  private JLabel jLabel33;
  private JLabel jLabel4;
  private JLabel jLabel5;
  private JLabel jLabel6;
  private JLabel jLabel7;
  private JLabel jLabel8;
  private JLabel jLabel9;
  private JRadioButton jRadioButton1;
  private JRadioButton jRadioButton10;
  private JRadioButton jRadioButton11;
  private JRadioButton jRadioButton12;
  private JRadioButton jRadioButton13;
  private JRadioButton jRadioButton14;
  private JRadioButton jRadioButton15;
  private JRadioButton jRadioButton16;
  private JRadioButton jRadioButton17;
  private JRadioButton jRadioButton18;
  private JRadioButton jRadioButton19;
  private JRadioButton jRadioButton2;
  private JRadioButton jRadioButton20;
  private JRadioButton jRadioButton21;
  private JRadioButton jRadioButton22;
  private JRadioButton jRadioButton3;
  private JRadioButton jRadioButton4;
  private JRadioButton jRadioButton5;
  private JRadioButton jRadioButton6;
  private JRadioButton jRadioButton7;
  private JRadioButton jRadioButton8;
  private JRadioButton jRadioButton9;
  private JTextField jTextField2;
  private JTextField jTextField3;

  public void init()
  {
    this.title = "车位开关量";
    ActionListener l = new ActionListener()
    {
      public void actionPerformed(ActionEvent e) {
        Object o = e.getSource();
        if ((o instanceof JRadioButton))
          BerthStationSwitchPanel.this.radioChanged();
      }
    };
    this.jRadioButton2.setSelected(true);
    this.jRadioButton4.setSelected(true);
    this.jRadioButton6.setSelected(true);
    this.jRadioButton8.setSelected(true);
    this.jRadioButton10.setSelected(true);
    this.jRadioButton12.setSelected(true);
    this.jRadioButton14.setSelected(true);
    this.jRadioButton16.setSelected(true);
    this.jRadioButton18.setSelected(true);
    this.jRadioButton20.setSelected(true);
    this.jRadioButton22.setSelected(true);
    this.jRadioButton1.addActionListener(l);
    this.jRadioButton2.addActionListener(l);
    this.jRadioButton3.addActionListener(l);
    this.jRadioButton4.addActionListener(l);
    this.jRadioButton5.addActionListener(l);
    this.jRadioButton6.addActionListener(l);
    this.jRadioButton7.addActionListener(l);
    this.jRadioButton8.addActionListener(l);
    this.jRadioButton9.addActionListener(l);
    this.jRadioButton10.addActionListener(l);
    this.jRadioButton11.addActionListener(l);
    this.jRadioButton12.addActionListener(l);
    this.jRadioButton13.addActionListener(l);
    this.jRadioButton14.addActionListener(l);
    this.jRadioButton15.addActionListener(l);
    this.jRadioButton16.addActionListener(l);
    this.jRadioButton17.addActionListener(l);
    this.jRadioButton18.addActionListener(l);
    this.jRadioButton19.addActionListener(l);
    this.jRadioButton20.addActionListener(l);
    this.jRadioButton21.addActionListener(l);
    this.jRadioButton22.addActionListener(l);
    radioChanged();
  }

  public String getHexData() {
    return this.jTextField3.getText();
  }

  public BerthStationSwitchPanel()
  {
    initComponents();
  }

  public void radioChanged() {
    String binStr = "";
    binStr = binStr + (this.jRadioButton1.isSelected() ? "1" : "0");
    binStr = binStr + (this.jRadioButton3.isSelected() ? "1" : "0");
    binStr = binStr + "00";
    binStr = binStr + (this.jRadioButton5.isSelected() ? "1" : "0");
    binStr = binStr + (this.jRadioButton7.isSelected() ? "1" : "0");
    binStr = binStr + "00";
    binStr = binStr + (this.jRadioButton9.isSelected() ? "1" : "0");
    binStr = binStr + (this.jRadioButton11.isSelected() ? "1" : "0");
    binStr = binStr + "0";
    binStr = binStr + (this.jRadioButton13.isSelected() ? "1" : "0");
    binStr = binStr + (this.jRadioButton15.isSelected() ? "1" : "0");
    binStr = binStr + (this.jRadioButton17.isSelected() ? "1" : "0");
    binStr = binStr + (this.jRadioButton19.isSelected() ? "1" : "0");
    binStr = binStr + (this.jRadioButton21.isSelected() ? "1" : "0");
    String s = "";
    for(int i =0;i<binStr.length() ; i++){
        s = binStr.charAt(i) + s;
    }
    binStr = s;
    this.jTextField2.setText(binStr);
    this.jTextField3.setText(NumberUtil.binary2Hex(binStr, 2));
  }

  public void binaryDataChanged()
  {
  }

  public void hexDataChanged()
  {
  }

  private void initComponents()
  {
    this.buttonGroup1 = new ButtonGroup();
    this.buttonGroup2 = new ButtonGroup();
    this.buttonGroup3 = new ButtonGroup();
    this.buttonGroup4 = new ButtonGroup();
    this.buttonGroup5 = new ButtonGroup();
    this.buttonGroup6 = new ButtonGroup();
    this.buttonGroup7 = new ButtonGroup();
    this.buttonGroup8 = new ButtonGroup();
    this.buttonGroup9 = new ButtonGroup();
    this.buttonGroup10 = new ButtonGroup();
    this.buttonGroup11 = new ButtonGroup();
    this.jButton4 = new JButton();
    this.jRadioButton20 = new JRadioButton();
    this.jLabel33 = new JLabel();
    this.jRadioButton22 = new JRadioButton();
    this.jLabel32 = new JLabel();
    this.jRadioButton16 = new JRadioButton();
    this.jTextField2 = new JTextField();
    this.jRadioButton18 = new JRadioButton();
    this.jRadioButton17 = new JRadioButton();
    this.jRadioButton1 = new JRadioButton();
    this.jRadioButton15 = new JRadioButton();
    this.jRadioButton2 = new JRadioButton();
    this.jRadioButton21 = new JRadioButton();
    this.jRadioButton19 = new JRadioButton();
    this.jLabel2 = new JLabel();
    this.jTextField3 = new JTextField();
    this.jButton5 = new JButton();
    this.jRadioButton14 = new JRadioButton();
    this.jRadioButton12 = new JRadioButton();
    this.jLabel6 = new JLabel();
    this.jLabel3 = new JLabel();
    this.jLabel7 = new JLabel();
    this.jLabel5 = new JLabel();
    this.jLabel8 = new JLabel();
    this.jRadioButton7 = new JRadioButton();
    this.jLabel9 = new JLabel();
    this.jRadioButton8 = new JRadioButton();
    this.jLabel10 = new JLabel();
    this.jRadioButton6 = new JRadioButton();
    this.jLabel11 = new JLabel();
    this.jRadioButton3 = new JRadioButton();
    this.jLabel12 = new JLabel();
    this.jRadioButton5 = new JRadioButton();
    this.jLabel4 = new JLabel();
    this.jRadioButton10 = new JRadioButton();
    this.jRadioButton4 = new JRadioButton();
    this.jRadioButton13 = new JRadioButton();
    this.jRadioButton9 = new JRadioButton();
    this.jRadioButton11 = new JRadioButton();

    this.jButton4.setText("确定");

    this.buttonGroup10.add(this.jRadioButton20);
    this.jRadioButton20.setText("0");

    this.jLabel33.setText("十六进制");

    this.buttonGroup11.add(this.jRadioButton22);
    this.jRadioButton22.setText("0");

    this.jLabel32.setText("二进制");

    this.buttonGroup8.add(this.jRadioButton16);
    this.jRadioButton16.setText("0");

    this.buttonGroup9.add(this.jRadioButton18);
    this.jRadioButton18.setText("0");

    this.buttonGroup9.add(this.jRadioButton17);
    this.jRadioButton17.setText("1");

    this.buttonGroup1.add(this.jRadioButton1);
    this.jRadioButton1.setText("1");

    this.buttonGroup8.add(this.jRadioButton15);
    this.jRadioButton15.setText("1");

    this.buttonGroup1.add(this.jRadioButton2);
    this.jRadioButton2.setText("0");

    this.buttonGroup11.add(this.jRadioButton21);
    this.jRadioButton21.setText("1");

    this.buttonGroup10.add(this.jRadioButton19);
    this.jRadioButton19.setText("1");

    this.jLabel2.setText("脚踏开关");

    this.jButton5.setText("确定");

    this.buttonGroup7.add(this.jRadioButton14);
    this.jRadioButton14.setText("0");

    this.buttonGroup6.add(this.jRadioButton12);
    this.jRadioButton12.setText("0");

    this.jLabel6.setText("机器人1急停");

    this.jLabel3.setText("安防继电器");

    this.jLabel7.setText("机器人2急停");

    this.jLabel5.setText("压力开关2");

    this.jLabel8.setText("控制台电源开关");

    this.buttonGroup4.add(this.jRadioButton7);
    this.jRadioButton7.setText("1");

    this.jLabel9.setText("车辆换电按钮");

    this.buttonGroup4.add(this.jRadioButton8);
    this.jRadioButton8.setText("0");

    this.jLabel10.setText("电池中转按钮");

    this.buttonGroup3.add(this.jRadioButton6);
    this.jRadioButton6.setText("0");

    this.jLabel11.setText("急停");

    this.buttonGroup2.add(this.jRadioButton3);
    this.jRadioButton3.setText("1");

    this.jLabel12.setText("暂停");

    this.buttonGroup3.add(this.jRadioButton5);
    this.jRadioButton5.setText("1");

    this.jLabel4.setText("压力开关1");

    this.buttonGroup5.add(this.jRadioButton10);
    this.jRadioButton10.setText("0");

    this.buttonGroup2.add(this.jRadioButton4);
    this.jRadioButton4.setText("0");

    this.buttonGroup7.add(this.jRadioButton13);
    this.jRadioButton13.setText("1");

    this.buttonGroup5.add(this.jRadioButton9);
    this.jRadioButton9.setText("1");

    this.buttonGroup6.add(this.jRadioButton11);
    this.jRadioButton11.setText("1");

    GroupLayout layout = new GroupLayout(this);
    setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(1)
      .add(layout.createSequentialGroup()
      .add(22, 22, 22)
      .add(layout.createParallelGroup(1)
      .add(layout.createSequentialGroup()
      .add(layout.createParallelGroup(2)
      .add(layout.createSequentialGroup()
      .add(this.jLabel7)
      .add(159, 159, 159)
      .add(this.jRadioButton12))
      .add(layout.createSequentialGroup()
      .add(this.jLabel6)
      .add(159, 159, 159)
      .add(this.jRadioButton10)))
      .addPreferredGap(0, -1, 32767)
      .add(this.jButton5))
      .add(layout.createSequentialGroup()
      .add(layout.createParallelGroup(2, false)
      .add(layout.createSequentialGroup()
      .add(this.jLabel12)
      .addPreferredGap(0, -1, 32767)
      .add(this.jRadioButton21))
      .add(layout.createSequentialGroup()
      .add(this.jLabel11)
      .addPreferredGap(0, -1, 32767)
      .add(this.jRadioButton19))
      .add(layout.createSequentialGroup()
      .add(this.jLabel10)
      .addPreferredGap(0, -1, 32767)
      .add(this.jRadioButton17))
      .add(layout.createSequentialGroup()
      .add(this.jLabel9)
      .addPreferredGap(0, -1, 32767)
      .add(this.jRadioButton15))
      .add(layout.createSequentialGroup()
      .add(this.jLabel8)
      .addPreferredGap(0, 48, 32767)
      .add(this.jRadioButton13))
      .add(layout.createSequentialGroup()
      .add(this.jLabel5)
      .addPreferredGap(0, -1, 32767)
      .add(this.jRadioButton7))
      .add(layout.createSequentialGroup()
      .add(this.jLabel4)
      .addPreferredGap(0, -1, 32767)
      .add(this.jRadioButton5))
      .add(layout.createSequentialGroup()
      .add(this.jLabel3)
      .addPreferredGap(0, -1, 32767)
      .add(this.jRadioButton3))
      .add(layout.createSequentialGroup()
      .add(this.jLabel2)
      .addPreferredGap(0, -1, 32767)
      .add(this.jRadioButton1))
      .add(layout.createSequentialGroup()
      .add(0, 0, 32767)
      .add(layout.createParallelGroup(2)
      .add(this.jRadioButton11)
      .add(this.jRadioButton9))))
      .add(65, 65, 65)
      .add(layout.createParallelGroup(1)
      .add(this.jRadioButton22)
      .add(this.jRadioButton20)
      .add(this.jRadioButton18)
      .add(this.jRadioButton16)
      .add(this.jRadioButton14)
      .add(layout.createSequentialGroup()
      .add(this.jRadioButton4)
      .add(70, 70, 70)
      .add(this.jTextField2))
      .add(layout.createSequentialGroup()
      .add(layout.createParallelGroup(1)
      .add(this.jRadioButton8)
      .add(this.jRadioButton6)
      .add(this.jRadioButton2))
      .add(layout.createParallelGroup(1)
      .add(layout.createSequentialGroup()
      .add(70, 70, 70)
      .add(layout.createParallelGroup(1)
      .add(this.jTextField3)
      .add(layout.createSequentialGroup()
      .add(layout.createParallelGroup(1)
      .add(this.jLabel32)
      .add(this.jLabel33))
      .add(0, 64, 32767))))
      .add(2, 
      layout.createSequentialGroup().addPreferredGap(0, -1, 32767)
      .add(this.jButton4)))))))
      .addContainerGap()));

    layout.setVerticalGroup(
      layout.createParallelGroup(1)
      .add(layout.createSequentialGroup()
      .add(layout.createParallelGroup(1, false)
      .add(layout.createSequentialGroup()
      .add(26, 26, 26)
      .add(layout.createParallelGroup(1)
      .add(2, this.jRadioButton1)
      .add(layout.createParallelGroup(3)
      .add(this.jLabel2)
      .add(this.jRadioButton2)))
      .add(18, 18, 18)
      .add(layout.createParallelGroup(3)
      .add(this.jLabel3)
      .add(this.jRadioButton3)
      .add(this.jRadioButton4))
      .add(18, 18, 18)
      .add(layout.createParallelGroup(3)
      .add(this.jLabel4)
      .add(this.jRadioButton5)
      .add(this.jRadioButton6))
      .add(31, 31, 31)
      .add(layout.createParallelGroup(3)
      .add(this.jLabel5)
      .add(this.jRadioButton7)
      .add(this.jRadioButton8))
      .add(18, 18, 18)
      .add(layout.createParallelGroup(3)
      .add(this.jLabel6)
      .add(this.jRadioButton9)
      .add(this.jRadioButton10)))
      .add(layout.createSequentialGroup()
      .add(39, 39, 39)
      .add(this.jLabel32)
      .add(18, 18, 18)
      .add(this.jTextField2, -2, -1, -2)
      .add(18, 18, 18)
      .add(this.jButton4)
      .addPreferredGap(0, -1, 32767)
      .add(this.jLabel33)
      .add(18, 18, 18)
      .add(this.jTextField3, -2, -1, -2)))
      .add(18, 18, 18)
      .add(layout.createParallelGroup(3)
      .add(this.jLabel7)
      .add(this.jRadioButton11)
      .add(this.jRadioButton12)
      .add(this.jButton5))
      .add(18, 18, 18)
      .add(layout.createParallelGroup(3)
      .add(this.jLabel8)
      .add(this.jRadioButton13)
      .add(this.jRadioButton14))
      .add(18, 18, 18)
      .add(layout.createParallelGroup(3)
      .add(this.jRadioButton15)
      .add(this.jRadioButton16)
      .add(this.jLabel9))
      .add(18, 18, 18)
      .add(layout.createParallelGroup(3)
      .add(this.jLabel10)
      .add(this.jRadioButton17)
      .add(this.jRadioButton18))
      .add(18, 18, 18)
      .add(layout.createParallelGroup(3)
      .add(this.jLabel11)
      .add(this.jRadioButton19)
      .add(this.jRadioButton20))
      .add(18, 18, 18)
      .add(layout.createParallelGroup(3)
      .add(this.jLabel12)
      .add(this.jRadioButton21)
      .add(this.jRadioButton22))
      .addContainerGap(-1, 32767)));
  }
}